package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ykdl.member.kid.R;
import com.ykdl.member.base.GlobalContext;
import com.ykdl.member.kid.gears.HomeActivity;
import com.ykdl.member.kid.util.DateUtil;

public class IaskDocCircleAdapter extends BaseAdapter implements OnClickListener {
	ArrayList<Object> list = null;
	private HomeActivity mContext ;
	public IaskDocCircleAdapter(HomeActivity context){
		this.mContext = context;
	}
	public void setList(ArrayList<Object> list) {
		this.list = list;
	}

	public ArrayList<Object> getList() {
		return list;
	}
	@Override
	public int getCount() {
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		if (getCount() != 0) {
			return list.get(position);
		} else {
			return null;
		}

	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	@Override
	public int getItemViewType(int position) {
		return position;
//		IaskQuestionBean bean = (IaskQuestionBean) list.get(position);
//		if (bean.getType().equals("5")) {
//			return 1;
//		} else {
//			return 2;
//		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder1 holder1 = null;
		ViewHolder2 holder2 = null;
		int type = getItemViewType(position);
		if (convertView == null) {
			if (type == 1) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.iask2_doc_item1, null);
				holder1 = new ViewHolder1();
				setView1(holder1, convertView);
				convertView.setTag(holder1);
			} else {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.iask2_doc_item2, null);
				holder2 = new ViewHolder2();
				setView2(holder2, convertView);
				convertView.setTag(holder2);
			}
		} else {
			if (type == 1) {
				holder1 = (ViewHolder1) convertView.getTag();
			} else {
				holder2 = (ViewHolder2) convertView.getTag();
			}
		}
		if (type == 1) {// 医生发布的话题
			
		} else {
			
		}
		return convertView;

	}


	public void setView1(ViewHolder1 holder, View view) {
		holder.item_content = (TextView) view
				.findViewById(R.id.item_question_content);
		holder.head = (ImageView) view.findViewById(R.id.head);
		holder.head.setOnClickListener(this);
		holder.name = (TextView) view.findViewById(R.id.name);
		holder.item_time = (TextView) view.findViewById(R.id.item_time);
	}

	public void setView2(ViewHolder2 holder, View view) {
		holder.item_question_content = (TextView) view
				.findViewById(R.id.item_question_content);
		holder.item_answer_content = (TextView) view
				.findViewById(R.id.item_answer_content);
		holder.head = (ImageView) view.findViewById(R.id.head);
		holder.head.setOnClickListener(this);
		holder.name = (TextView) view.findViewById(R.id.name);
		holder.item_age = (TextView) view.findViewById(R.id.item_age);
		holder.item_time = (TextView) view.findViewById(R.id.item_time);
	}

	@Override
	public void onClick(View v) {
		if (v.getTag() != null) {
		}

	}
	class ViewHolder1 {
		TextView item_content;
		ImageView item_zhiding;
		ImageView item_topic;
		ImageView head;
		TextView name;
		TextView item_time;
		TextView item_collect;
	}

	class ViewHolder2 {
		TextView item_question_content;
		TextView item_answer_content;
		ImageView head;
		TextView name;
		TextView item_age;
		TextView item_time;
		TextView item_collect;
	}
}
